|
|
|
|
|
|
|
Then the X coordinates on the drawing object range from 0 to 0 + 9 = 9, and the Y coordinates range from 110 to 110 + (120) = 10. Because Y coordinates are measured from the top down, this means that the topmost point in the drawing area has a Y coordinate of 110, and the bottommost point in the drawing area has a Y coordinate of 10. |
|
|
|
|
|
|
|
|
This arrangement is more in keeping with intuition: Larger Y coordinates are at the top of the drawing area, and smaller Y coordinates are at the bottom. This also makes drawing the bar chart easy. For the Kth data value, the program simply draws a box with X coordinates ranging from K to K + 1, and Y coordinates ranging from 0 to the value of the Kth data item. |
|
|
|
|
|
|
|
|
Example program Bars uses this method to draw a bar chart like the one shown in Figure 1.2. When the program starts, it stores some random values in the DataValue array. When the form is resized, including when it is first created, the program redefines its coordinate system to match the data values. It clears its form and redraws the bar chart using the following code. (Do not worry too much about the drawing commands just yet. They are described later in this chapter. For now, just concentrate on the scale commands and the coordinates used to draw the bars.) |
|
|
|
 |
|
|
|
|
Option Explicit
Private Const NUM_VALUES = 7
Private DataValue(1 To NUM_VALUES) As Integer
' Create some random data. Private Sub Form_Load()
Dim i As Intege
Randomize
For i = 1 To NUM_VALUES
DataValue(i) = Rnd * 100 |
|
|
|
|
|